﻿Namespace OpenArchive
    Namespace System
        Namespace DB
            Public Class WeakReferenceList
                Private m_dictionary As Dictionary(Of Int32, KeyValuePair(Of Long, WeakReference))

                Public Sub New()
                    m_dictionary = New Dictionary(Of Int32, KeyValuePair(Of Long, WeakReference))
                End Sub

                Public Sub Add(ByVal DocID As Long, ByVal obj As Object)
                    Dim _hashcode As Integer = obj.GetHashCode
                    Dim _weakref As New WeakReference(obj)
                    m_dictionary.Add(_hashcode, New Generic.KeyValuePair(Of Long, WeakReference)(DocID, _weakref))

                    For Each _keyValue As Generic.KeyValuePair(Of Int32, KeyValuePair(Of Long, WeakReference)) In m_dictionary
                        If Not _keyValue.Value.Value.IsAlive Then
                            m_dictionary.Remove(_keyValue.Key)
                        End If
                    Next
                End Sub
                Public Function GetDocID(ByVal Key As Integer) As Long
                    Return m_dictionary.Item(Key).Key
                End Function
            End Class
        End Namespace
    End Namespace
End Namespace